/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import sys.bean.ClienteBean;
import sys.bean.ProdutoPedidoBean;
import sys.bean.PedidoBean;
import sys.bean.ProdutoBean;
import sys.dao.ClienteDao;
import sys.dao.ProdutoPedidoDao;
import sys.dao.PedidoDao;
import sys.utils.Mensagens;
import sys.utils.Utils;

/**
 *
 * @author Administrador
 */
public class CCapturaPedidos extends javax.swing.JDialog {

    SimpleDateFormat formDataSpac = new SimpleDateFormat("yyyyMMdd");
    NumberFormat formatoMoeda = NumberFormat.getCurrencyInstance();

    ClienteBean cliente;
    ProdutoBean produto;

    PedidoDao daoPedido = new PedidoDao();
    ProdutoPedidoDao DaoItensPedido = new ProdutoPedidoDao();
    ClienteDao daoCliente = new ClienteDao();

    List<PedidoBean> listaPedidosConcreteira = new ArrayList<>();
    List<String> listaProdutos;

    Utils util = new Utils();

    /**
     * Creates new form CCapturaPedidos
     *
     * @param parent
     * @param modal
     */
    public CCapturaPedidos(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        dataInicial.setDate(new Date());
        dataFinal.setDate(new Date());
        Utils.escClose(this);
        btnImportar.setEnabled(false);
    }

    public CCapturaPedidos(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
        initComponents();
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        setLocationRelativeTo(null);
        dataInicial.setDate(new Date());
        dataFinal.setDate(new Date());
        Utils.escClose(this);
        btnImportar.setEnabled(false);
    }

    public String formatoMoeda(double valor) {
        return formatoMoeda.format(valor).replace("R$", "");
    }

    private void importarDados() {

        try {
            daoCliente.insertClienMySql(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 2).toString());
        } catch (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
            try {
                daoCliente.updateClienMySql(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 2).toString());
            } catch (SQLException | IOException ex) {
                Mensagens.msgErro("erro ao capturar dados do cliente\n" + ex.getMessage());
                ex.printStackTrace();
            }

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao capturar dados do pedido\n" + ex.getMessage());
            ex.printStackTrace();
        }

        try {
            daoPedido.insertPedidoMySql(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 1).toString());
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao capturar dados do pedido\n" + ex.getMessage());
            ex.printStackTrace();
        }

        try {
            DaoItensPedido.insertItensPedidoMySql(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 1).toString());
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao capturar dados do pedido\n" + ex.getMessage());
            ex.printStackTrace();
        }
    }

    private void atualizaTabelaItensPedido() {

        DefaultTableModel modelo = (DefaultTableModel) tabelaItemPedido.getModel();
        modelo.setNumRows(0);

        try {
            for (ProdutoPedidoBean iPed : ProdutoPedidoDao.itensPedidoConcreteira(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 1).toString())) {
                modelo.addRow(new Object[]{
                    iPed.getProduto().getCodigo() + "-" + iPed.getProduto().getDescricao(), formatoMoeda(iPed.getQtdProdutoCompra()), formatoMoeda(iPed.getPvenda()), formatoMoeda(iPed.getQtdProdutoCompra() * iPed.getPvenda())
                });
            }

            DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();

            centralizado.setHorizontalAlignment(SwingConstants.CENTER);

            tabelaItemPedido.getColumnModel().getColumn(1).setCellRenderer(centralizado);
            tabelaItemPedido.getColumnModel().getColumn(2).setCellRenderer(centralizado);
            tabelaItemPedido.getColumnModel().getColumn(3).setCellRenderer(centralizado);

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao atualizar tabela de pedidos\n" + ex.getMessage());
        }
    }

    private void atualizaTabelaPedidos() {

        DefaultTableModel modelo = (DefaultTableModel) tabelaPedidos.getModel();
        modelo.setNumRows(0);

        try {
            listaProdutos = util.listaProdutosConcreteira();
            System.out.println(listaProdutos.size());

            for (String codProduto : listaProdutos) {
                for (PedidoBean ped : PedidoDao.vendaProdutosConcreteira(formDataSpac.format(dataInicial.getDate()), formDataSpac.format(dataFinal.getDate()), codProduto)) {
                    listaPedidosConcreteira.add(ped);
                }
            }

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao carregar produtos da concreteira\n" + ex.getMessage());
        }

        for (PedidoBean p : listaPedidosConcreteira) {
            modelo.addRow(new Object[]{
                p.getData(), p.getPedido(), p.getCliente().getCodigo(), p.getCliente().getNome(), p.getUsuario().getNome()
            });
        }

        DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
        centralizado.setHorizontalAlignment(SwingConstants.CENTER);
        tabelaPedidos.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        tabelaPedidos.getColumnModel().getColumn(1).setCellRenderer(centralizado);
        tabelaPedidos.getColumnModel().getColumn(2).setCellRenderer(centralizado);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jpDados = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        dataInicial = new com.toedter.calendar.JDateChooser("dd/MM/yyyy", "##/##/#####", '_');
        dataFinal = new com.toedter.calendar.JDateChooser("dd/MM/yyyy", "##/##/#####", '_');
        jPanel4 = new javax.swing.JPanel();
        btnSalvar = new javax.swing.JButton();
        btnImportar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaPedidos = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaItemPedido = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CAPTURAR PEDIDOS");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jpDados.setBackground(new java.awt.Color(255, 255, 255));
        jpDados.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SELECIONE DADOS:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel2.setText("DATA INICIAL:");

        jLabel3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel3.setText("DATA FINAL:");

        dataInicial.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        dataFinal.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N

        javax.swing.GroupLayout jpDadosLayout = new javax.swing.GroupLayout(jpDados);
        jpDados.setLayout(jpDadosLayout);
        jpDadosLayout.setHorizontalGroup(
            jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDadosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(dataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(dataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jpDadosLayout.setVerticalGroup(
            jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDadosLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(1, 1, 1)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(dataFinal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        btnSalvar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png"))); // NOI18N
        btnSalvar.setText("BUSCAR");
        btnSalvar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        jPanel4.add(btnSalvar);

        btnImportar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnImportar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/colete.png"))); // NOI18N
        btnImportar.setText("IMPORTAR");
        btnImportar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportarActionPerformed(evt);
            }
        });
        jPanel4.add(btnImportar);

        btnSair.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/sair.png"))); // NOI18N
        btnSair.setText("SAIR");
        btnSair.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel4.add(btnSair);

        jTabbedPane1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N

        tabelaPedidos.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaPedidos.setForeground(new java.awt.Color(51, 102, 255));
        tabelaPedidos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "DATA", "PEDIDO", "CODIGO", "CLIENTE", "VENDEDOR"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaPedidos.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaPedidos.getTableHeader().setReorderingAllowed(false);
        tabelaPedidos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaPedidosMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tabelaPedidosMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaPedidos);
        if (tabelaPedidos.getColumnModel().getColumnCount() > 0) {
            tabelaPedidos.getColumnModel().getColumn(2).setPreferredWidth(15);
            tabelaPedidos.getColumnModel().getColumn(3).setPreferredWidth(300);
            tabelaPedidos.getColumnModel().getColumn(4).setPreferredWidth(80);
        }

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 923, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("PEDIDOS", jPanel2);

        tabelaItemPedido.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaItemPedido.setForeground(new java.awt.Color(51, 102, 255));
        tabelaItemPedido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "PRODUTO", "QUANTIDADE", "VALOR UNT", "VALOR TOTAL"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaItemPedido.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaItemPedido.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabelaItemPedido);
        if (tabelaItemPedido.getColumnModel().getColumnCount() > 0) {
            tabelaItemPedido.getColumnModel().getColumn(0).setPreferredWidth(400);
        }

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 923, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("ITENS DO PEDIDO", jPanel3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed

        final BarraProgresso pb = new BarraProgresso(this);
        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {
                pb.gerarJanela();
                pb.lbDescricao.setText("ANALISANDO, POR FAVOR AGUARDE...");

                atualizaTabelaPedidos();

                return null;
            }

            @Override
            protected void done() {
                pb.fechar();
            }
        };
        worker.execute();

    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void tabelaPedidosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaPedidosMouseClicked
        if (tabelaPedidos.getSelectedRow() < 0) {
            btnImportar.setEnabled(false);
        } else {
            btnImportar.setEnabled(true);
        }

        if ((evt.getModifiers() & java.awt.event.MouseEvent.BUTTON3_MASK) != 0) {
            JPopupMenu menu = new JPopupMenu();
            JMenuItem item = new JMenuItem("ITENS DO PEDIDO");
            item.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png")));
            item.setFont(new java.awt.Font("Calibri", 0, 11));
            menu.add(item);
            item.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    jTabbedPane1.setSelectedIndex(1);
                    atualizaTabelaItensPedido();
                }
            });
            menu.show(evt.getComponent(), evt.getX(), evt.getY());
        }

    }//GEN-LAST:event_tabelaPedidosMouseClicked

    private void btnImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportarActionPerformed
        try {
            if (PedidoDao.verExistePedido(Integer.parseInt(tabelaPedidos.getValueAt(tabelaPedidos.getSelectedRow(), 1).toString()))) {
                Mensagens.msgErro("Pedido ja capturado!");
            } else {
                final BarraProgresso pb = new BarraProgresso(this);
                SwingWorker worker = new SwingWorker() {

                    @Override
                    protected Object doInBackground() throws Exception {
                        pb.gerarJanela();
                        pb.lbDescricao.setText("IMPORTANDO PEDIDO, AGUARDE...");
                        importarDados();
                        return null;
                    }

                    @Override
                    protected void done() {
                        pb.fechar();
                    }
                };
                worker.execute();
            }
        } catch (SQLException ex) {
            Mensagens.msgErro("erro ao verificar se pedido ja foi capturado.\n" + ex.getMessage());
        }


    }//GEN-LAST:event_btnImportarActionPerformed

    private void tabelaPedidosMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaPedidosMousePressed
        if (tabelaPedidos.getSelectedRow() < 0) {
            btnImportar.setEnabled(false);
        } else {
            btnImportar.setEnabled(true);
        }

        if ((evt.getModifiers() & java.awt.event.MouseEvent.BUTTON3_MASK) != 0) {
            JPopupMenu menu = new JPopupMenu();
            JMenuItem item = new JMenuItem("ITENS DO PEDIDO");
            item.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png")));
            item.setFont(new java.awt.Font("Calibri", 0, 11));
            menu.add(item);
            item.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    jTabbedPane1.setSelectedIndex(1);
                    atualizaTabelaItensPedido();
                }
            });
            menu.show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }//GEN-LAST:event_tabelaPedidosMousePressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnImportar;
    private javax.swing.JButton btnSair;
    private javax.swing.JButton btnSalvar;
    private com.toedter.calendar.JDateChooser dataFinal;
    private com.toedter.calendar.JDateChooser dataInicial;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel jpDados;
    private javax.swing.JTable tabelaItemPedido;
    private javax.swing.JTable tabelaPedidos;
    // End of variables declaration//GEN-END:variables
}
